package com.irishud.hudnavi;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.LinearLayout;

/**
 * Created by Administrator on 2016/10/17.
 */

public class MirrorLayout extends LinearLayout {
    boolean enable_mirror = true;

    public MirrorLayout(Context context) {
        super(context);
    }

    public MirrorLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MirrorLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        if(enable_mirror)
            canvas.scale(-1f,1f,getWidth()/2,getHeight()/2);
        super.dispatchDraw(canvas);
    }

    public void setMirrorable(boolean how){
        this.enable_mirror = how;
        invalidate();
    }
}
